package com.tsd.jxc.stock.service.impl;

import com.tsd.core.utils.HlpUtils;
import com.tsd.core.vo.PageBean;
import com.tsd.jxc.stock.dao.JxcStockQueMapper;
import com.tsd.jxc.stock.entity.JxcStockQue;
import com.tsd.jxc.stock.entity.JxcStockQueExt;
import com.tsd.jxc.stock.service.JxcStockQueService;
import com.tsd.service.BaseServiceImpl;
import com.tsd.system.entity.SysUser;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 描述：JxcStockQue 服务实现层
 *
 * @author Hillpool
 * @date 2022/08/17 14:14:28
 */
@Service
public class JxcStockQueServiceImpl extends BaseServiceImpl implements JxcStockQueService {

    @Resource
    private JxcStockQueMapper jxcStockQueMapper;

    @Override
    public JxcStockQue getJxcStockQueById(Long id) throws Exception {
        return jxcStockQueMapper.selectByPrimaryKey(id);
    }

    @Override
    public JxcStockQueExt queryBySid(String sid) throws Exception {
        return jxcStockQueMapper.selectBySid(sid);
    }

    @Override
    public void deleteJxcStockQues(List<String> list, SysUser opUser) throws Exception {
        for (String sid : list) {
            JxcStockQue old = jxcStockQueMapper.selectBySid(sid);
            super.checkEmpty(old, "该记录不存在");
            super.autoInjectBaseData(old, opUser, TYPE_DELETE);
            jxcStockQueMapper.updateByPrimaryKeySelective(old);
        }
    }

    @Override
    public void saveJxcStockQue(JxcStockQue record, SysUser opUser) throws Exception {
        if (HlpUtils.isEmpty(record.getId())) {
            super.autoInjectBaseData(record, opUser, this.TYPE_CREATE);
            jxcStockQueMapper.insertSelective(record);
        } else {
            super.autoInjectBaseData(record, opUser, this.TYPE_UPDATE);
            jxcStockQueMapper.updateByPrimaryKeySelective(record);
        }
    }

    @Override
    public List<JxcStockQueExt> findJxcStockQues(Map<String, Object> params, PageBean page) throws Exception {
        return jxcStockQueMapper.selectByPage(params, page);
    }

    @Override
    public List<JxcStockQueExt> findJxcStockQues(Map<String, Object> params) throws Exception {
        return jxcStockQueMapper.selectByParams(params);
    }
}